
module libeventd.Event ;

public import
	libeventd.Types ;

enum{
	EV_TIMEOUT=0x01,
	EV_READ	=0x02,
	EV_WRITE	=0x04,
	EV_SIGNAL	=0x08,
	EV_PERSIST=0x10,
	EV_ET      = 0x20,
}

enum event_method_feature {
    EV_FEATURE_ET = 0x01,
    EV_FEATURE_O1 = 0x02,
    EV_FEATURE_FDS = 0x04
}


enum event_base_config_flag {
	EVENT_BASE_FLAG_NOLOCK = 0x01,
	EVENT_BASE_FLAG_IGNORE_ENV = 0x02,
	EVENT_BASE_FLAG_STARTUP_IOCP = 0x04,
	EVENT_BASE_FLAG_NO_CACHE_TIME = 0x08
}

enum{
	_EVENT_LOG_DEBUG =0,
	_EVENT_LOG_MSG   =1,
	_EVENT_LOG_WARN  =2,
	_EVENT_LOG_ERR   =3,
}
const EVENT_MAX_PRIORITIES  = 256 ;

enum{
	EVLOOP_ONCE	=0x01,
	EVLOOP_NONBLOCK	= 0x02,
}


extern(C):

alias void function(ev_int severity, char *msg) event_log_cb;
alias void function(ev_int err) event_fatal_cb;
alias void function(evutil_socket_t, ev_short, void *) event_callback_fn;
alias void function(evutil_socket_t, ev_short, void *) event_set_cb;

void event_enable_debug_mode();
void event_debug_unassign( event *);
event_base *event_base_new();
ev_int event_reinit( event_base *base);
ev_int event_base_dispatch( event_base *);
char *event_base_get_method(  event_base *);
char **event_get_supported_methods();
event_config *event_config_new();
void event_config_free( event_config *cfg);
ev_int event_config_avoid_method( event_config *cfg, char *method);
ev_int event_base_get_features(  event_base *base);
ev_int event_config_require_features( event_config *cfg, ev_int feature);
ev_int event_config_set_flag( event_config *cfg, ev_int flag);
event_base *event_base_new_with_config(  event_config *);
void event_base_free( event_base *);
void event_set_log_callback(event_log_cb cb);
void event_set_fatal_callback(event_fatal_cb cb);
ev_int event_base_set( event_base *,  event *);
ev_int event_base_loop( event_base *, ev_int);
ev_int event_base_loopexit( event_base *,   timeval *);
ev_int event_base_loopbreak( event_base *);
ev_int event_base_got_exit( event_base *);
ev_int event_base_got_break( event_base *);
ev_int event_assign( event *,  event_base *, evutil_socket_t, ev_short, event_callback_fn, void *);
event *event_new( event_base *, evutil_socket_t, ev_short, event_callback_fn, void *);
void event_free( event *);
ev_int event_base_once( event_base *, evutil_socket_t, ev_short, event_callback_fn, void *,   timeval *);
ev_int event_add( event *,   timeval *);
ev_int event_del( event *);
void event_active( event *, ev_int, ev_short);
ev_int event_pending(  event *, ev_short,  timeval *);
ev_int _event_initialized(  event *, ev_int check_fd);
evutil_socket_t event_get_fd(  event *ev);
event_base *event_get_base(  event *ev);
ev_short event_get_events(  event *ev);
event_callback_fn event_get_callback(  event *ev);
void *event_get_callback_arg(  event *ev);
void event_get_assignment(  event *event,  event_base **base_out, evutil_socket_t *fd_out, ev_short *events_out, event_callback_fn *callback_out, void **arg_out);
size_t event_get_struct_event_size();
char *event_get_version();
ev_uint32_t event_get_version_number();
ev_int event_base_priority_init( event_base *, ev_int);
ev_int event_priority_set( event *, ev_int);
timeval* event_base_init_common_timeout( event_base *base,  timeval *duration);
version(_EVENT_DISABLE_MM_REPLACEMENT){
void event_set_mem_functions(void *(*malloc_fn)(size_t sz), void *(*realloc_fn)(void *ptr, size_t sz),  void (*free_fn)(void *ptr));
version = EVENT_SET_MEM_FUNCTIONS_IMPLEMENTED;
}
// void event_base_dump_events( event_base *,  FILE*);
ev_int event_base_gettimeofday_cached( event_base *base,  timeval *tv);

/* compat */
event_base *event_init();
ev_int event_dispatch();
ev_int event_loop(ev_int);
ev_int event_loopexit(  timeval *);
ev_int event_loopbreak();
ev_int event_once(evutil_socket_t , ev_short, void (*)(evutil_socket_t, ev_short, void *), void *,   timeval *);
char *event_get_method();
ev_int event_priority_init(ev_int);
void event_set( event *, evutil_socket_t, ev_short, event_set_cb, void *);

/* macro */
alias event_add	evtimer_add;
alias event_del	evtimer_del;
void evtimer_set(event* ev, event_set_cb cb, void* arg ){
	return event_set(ev, -1, 0, cb, arg);
}
void evsignal_set(event* ev, evutil_socket_t x, event_set_cb cb, void* arg ){
	return event_set(ev,x, EV_SIGNAL|EV_PERSIST, cb, arg) ;
}
